﻿Imports System.Reflection
Imports TNValidate

Namespace AboutDNN.DNNMVC

    Public Class DNNAccount
        Inherits BaseModel


        Public UserName As String = ""
        Public FirstName As String = "" ' "FirstName"
        Public LastName As String = "" ' "LastName"
        Public Email As String = "" '  "email@email.com"
        Public Password As String = "" ' "password"

        Public CompanyName As String = "" ' "companyname"

        Public Address As String = ""
        Public City As String = ""
        Public State As String = ""
        Public Zip As String = ""
        Public Country As String = "US"
        Public Phone As String = ""
        Public Fax As String = ""

        Public AddToRoles As New List(Of String)

        Public ReadOnly Property DisplayName() As String
            Get
                Return FirstName & " " & LastName
            End Get
        End Property

        Public Overrides Sub ExecuteValidation()
            Validate.Clear()
            Validate.That(UserName, "UserName").IsNotEmpty()
            Validate.That(FirstName, "FirstName").IsNotEmpty()
            Validate.That(LastName, "LastName").IsNotEmpty()
            Validate.That(Email, "Email").IsNotEmpty.IsEmail()
            Validate.That(Password, "Password").IsNotEmpty()
            Validate.That(Password, "Password").IsLongerThan(7)
            ' Validate that the user does not exist in dnn
            If String.IsNullOrEmpty(UserName) = False Then
                If App.DB.UserExists(UserName) Then
                    Validate.AddValidationError("This e-mail is already being used in the system.", "UserName", -1)
                End If
            End If
        End Sub

    End Class


    Public Enum DNNUserCreateStatus

        AddUser = 0
        UsernameAlreadyExists = 1
        UserAlreadyRegistered = 2
        DuplicateEmail = 3
        DuplicateProviderUserKey = 4
        DuplicateUserName = 5
        InvalidAnswer = 6
        InvalidEmail = 7
        InvalidPassword = 8
        InvalidProviderUserKey = 9
        InvalidQuestion = 10
        InvalidUserName = 11
        ProviderError = 12
        Success = 13
        UnexpectedError = 14
        UserRejected = 15
        PasswordMismatch = 16
        AddUserToPortal = 17

    End Enum

End Namespace